package engine.scene
{
	import engine.control.MainSpaceControl;
	import engine.logic.ArrowGuideLogic;
	import engine.logic.loading.LoadingLogic;
	import engine.ui.MainUIManager;
	import engine.ui.UIManage;
	
	import flash.display.Stage;
	import flash.events.Event;
	
	import newx.StageInfo;

	/**
	 *	场景改变管理 
	 */
	public class SceneChangeManager
	{
		//舞台
		private var _stage		:Stage;
		
		public function SceneChangeManager()
		{
			init();
		}
		
		private function init():void
		{
			_stage	=	StageInfo.stage;
			
			addListener();
		}
		
		private function addListener():void
		{
			_stage.addEventListener(Event.RESIZE, onResize);
		
			onResize();
		}
		
		private function onResize(evt : Event = null):void
		{
			//滚动条改变
			MainSpaceControl.getInstance().onResize();
			
			//主界面改变
			MainUIManager.getInstance().onStageReSize();
			
			SceneManager.getInstance().onChangeSize();
			
			//界面改变
			UIManage.getInstance().onStageReSize();
			
			ArrowGuideLogic.getInstance().changeSize();
		}
		
		/**
		 *	全屏，顶部偏移值 
		 */		
		public static var topOffsize : int = -151;
		/**
		 *  全屏，顶部导航栏高度 
		 */		
		public static var indexTopHeight:Number = 0;
		/**
		 *  全屏，底部导航栏高度 
		 */		
		public static var indexBottomHeight:Number = 139; 		
		
		/**
		 *	获得当前游戏宽度，最小1000 
		 * @return int
		 */		
		public static function getGameWidth():int
		{
			return Math.min(Math.max(StageInfo.stage.stageWidth, StageInfo.rootW), StageInfo.rootMaxW);
		}
		
		/**
		 * 获得当前游戏高度，最小600 
		 * @return int
		 */
		public static function getGameHeight():int
		{
			return Math.min(Math.max(StageInfo.stage.stageHeight, StageInfo.rootH), StageInfo.rootMaxH);
		}
		
		/**
		 *	场景高度与游戏最大高度的间距 
		 * @return int
		 * 
		 */
		public static function getGameMaxHeightOffsize():int
		{
			return (StageInfo.rootMaxH - getGameHeight()) * .5;
		}
		
		/**
		 *	场景宽度与游戏最大宽度的间距 
		 * @return int
		 * 
		 */
		public static function getGameMaxWidhtOffsize():int
		{
			return (StageInfo.rootMaxW - getGameWidth()) * .5;
		}
		
		/**
		 *	场景高度与游戏最小高度的间距 
		 * @return int
		 * 
		 */
		public static function getGameMinHeightOffsize():int
		{
			return (StageInfo.rootH - getGameHeight()) * .5;
		}
		
		/**
		 *	场景宽度与游戏最小宽度的间距 
		 * @return int
		 * 
		 */
		public static function getGameMinWidhtOffsize():int
		{
			return (StageInfo.rootW - getGameWidth()) * .5 ;
		}
		
		/**
		 *	游戏Y轴 
		 * @return 
		 * 
		 */
		public static function getGameY():int
		{
			var uiY : int	=	0;
			if(StageInfo.stage.stageHeight > StageInfo.rootMaxH)
			{//场景大于768
				uiY	=	StageInfo.rootH - StageInfo.rootMaxH;
			}
			else if(StageInfo.stage.stageHeight <= StageInfo.rootH)
			{//场景小于1000的时候
				uiY	=	0;
			}else
			{ //600-768之间
				uiY	=	- StageInfo.mainSpace.y;
			}
			return uiY;
		}
		
		public static function getGameX():int
		{
			//场景宽度
			var viewWidth	: int = SceneChangeManager.getGameWidth();
			var xPoint		: int;
			if(viewWidth < StageInfo.rootMaxW)
			{
				xPoint =  (StageInfo.rootW - viewWidth) >> 1;
			}
			else
			{//右越界
				xPoint =  (StageInfo.rootW - StageInfo.rootMaxW) >> 1;
			}
			
			return xPoint;
		}
		
		/**
		 *	贴右边坐标 
		 */
		public static function rightPoint():int
		{
			var xPoint : int;
			
			if(StageInfo.stage.stageWidth <= StageInfo.rootW)
			{
				xPoint	=	0;
			}else
			{
				xPoint	=	Math.abs((StageInfo.rootW - Math.min(getGameWidth(), attackSceneViewWidth)) * .5);
			}
			
			return xPoint;
		}
		
		public static var attackSceneViewWidth : int	=	1280;
		
		public static var attackSceneViewHeight : int	=	768;
		
		public static var attackSceneViewX : int	=	-40;
		
		public static var attackSceneViewY : int	=	-168;
	}
}